/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package pl.cezary.butler.walili.common;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Date;
import org.springframework.jdbc.core.RowMapper;
import pl.cezary.butler.walili.server.db.tables.ZadReszta;

/**
 *
 * @author czarek
 */
public class ZadResztaVO {
    private final int id_reszta;
    private final String cel;
    private final String celUrl;
    private final TaskStatus status;    
    private final int priorytet;
    private final int id_user;
    private final Date data_przetwarzania;
    private final String mime_type;

    public ZadResztaVO(int id_reszta, String cel, String celUrl, int status,  int priorytet, int id_user, Date data_przetwarzania, String mime_type) {
        this.cel = cel;
        this.celUrl = celUrl;
        this.status = TaskStatus.values()[status];
        this.id_reszta = id_reszta;
        this.priorytet = priorytet;
        this.id_user = id_user;
        this.data_przetwarzania = data_przetwarzania;
        this.mime_type = mime_type;
    }    
    
    private static final RowMapper<ZadResztaVO> ROW_MAPPER = new ZadResztaRowMapper();
    
    public static RowMapper<ZadResztaVO> getRowMapper(){
        return ROW_MAPPER;
    }

    public String getCel() {
        return cel;
    }

    public String getCelUrl() {
        return celUrl;
    }

    public Date getDataPrzetwarzania() {
        return data_przetwarzania;
    }

    public int getIdReszta() {
        return id_reszta;
    }

    public int getIdUser() {
        return id_user;
    }

    public String getMimeType() {
        return mime_type;
    }

    public int getPriorytet() {
        return priorytet;
    }

    public TaskStatus getStatus() {
        return status;
    }
    
    

    private static class ZadResztaRowMapper implements RowMapper<ZadResztaVO>{

        @Override
        public ZadResztaVO mapRow(ResultSet rs, int rowNum) throws SQLException {
            return new ZadResztaVO(rs.getInt(ZadReszta.id_reszta.name()),
                    rs.getString(ZadReszta.cel.name()),
                    rs.getString(ZadReszta.celUrl.name()),
                    rs.getInt(ZadReszta.status.name()),
                    rs.getInt(ZadReszta.priorytet.name()),
                    rs.getInt(ZadReszta.id_user.name()),
                    rs.getDate(ZadReszta.data_przetwarzania.name()),
                    rs.getString(ZadReszta.mime_type.name())
                    );
        }
               
    }
    
    
}
